<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/static/commons/taglibs.jsp"%>
<%@ include file="/static/commons/meta.jsp"%>
<%@ include file="/static/commons/jquery-easyui.jsp" %>
<html xmlns="http://www.w3.org/1999/xhtml">
 <head>
 	<title>${title }</title>
	<!--自定义index样式-->
	<link rel="stylesheet" href="${ctx }/static/styles/basic/basic.css" ></link>
	<link rel="stylesheet" href="${ctx }/static/styles/edit/tableStyle.css"></link>
	<link rel="stylesheet" href="${ctx }/static/scripts/autocomplete/autocomplate.css" ></link>
	<!--js库-->
	<script type="text/javascript" src="${ctx}/static/scripts/set_select.js"></script>
	<script type="text/javascript" src="${ctx}/static/scripts/check_all.js"></script>
	<style type="text/css">
		.add_icon{background: url(${ctx}/static/images/common/plus_minus.jpg) left 0px no-repeat; width: 14px; height: 15px;cursor: pointer; float: right; margin: 7px 15px 0px 0px; }
		.dev_icon{background: url(${ctx}/static/images/common/plus_minus.jpg) right 0px no-repeat; width: 14px; height: 15px;cursor: pointer; float: right; margin: 7px 15px 0px 0px; display: none; }
		.search_icon{background: url(${ctx}/static/images/head/search.png) no-repeat 1px 50% #c0c0c0;border-radius: 5px;border:1px solid #ccc; width: 20px; height: 20px;cursor: pointer;float:right;margin: 5px 5px 0px 0px}
		.search_icon:HOVER{background-color: #ccc;}
		tr.error{color: red;}
	</style>
	<script type="text/javascript">
		var headers = {};
		headers['__RequestVerificationToken'] = "${RequestVerificationToken}";
	</script>
  </head>
  
  <body style="padding:8px;">
  		<form id="editForm" action="${ctx}/myInspect/save" method="post">
  			<input type="hidden" id="equId" name="p_equId" data-field="equ_id" class="echo"></input>
  			<input type="hidden" id="orderId" name="p_orderId" data-field="order_id" class="echo"></input>
			<table id="tag1" class="table-ltr">
				<tbody>
					<tr>
						<td>送检单位：</td>
						<td><vvise:select id="custId" name="p_custId" sqlname="getCust" defval="${obj.custId }" ifSelect="false" /></td>
						<td>检定日期：</td>
						<td>${inspectDate }</td>
						<td class="non-empty">地点：</td>
						<td><input type="text" id="address" name="p_address"></input></td>
					</tr>
					<tr>
						<td class="non-empty">仪器编号：</td>
						<td><input type="text" id="deviceNo" name="p_deviceNo" data-field="device_no" class="echo" autocomplete="off" style="width: 115px" placeholder="模糊搜索"></input>
							<div class="search_icon" title="查询"></div></td>
						<td>类型：</td>
						<td <c:if test="${obj.deviceType eq 2}">colspan="3"</c:if>><vvise:select id="deviceType" name="p_deviceType" sqlname="getCodeData" sqlparam="device_type" defval="${obj.deviceType }" ifSelect="false" /></td>
						<c:if test="${obj.deviceType eq 1}">
							<td>容积：</td>
							<td><input type="text" data-field="volume_category_" class="echo" disabled="disabled"></input></td>
						</c:if>
						<c:if test="${obj.deviceType eq 3}">
							<td>气体种类：</td>
							<td><input type="text" data-field="gas_type_" class="echo" disabled="disabled"></input></td>
						</c:if>
						
						<!-- <td>气体种类：</td>
						<td><input type="text" data-field="gas_type_" class="echo" disabled="disabled"></input></td> -->
					</tr>
					<tr>
						<td>名称：</td>
						<td><input type="text" data-field="device_name" class="echo" disabled="disabled"></input></td>
						<td>生产厂家：</td>
						<td><input type="text" data-field="device_manufactor" class="echo" disabled="disabled"></input></td>
						<c:if test="${obj.deviceType eq 1}">
							<td>出厂日期：</td>
							<td><input type="text" data-field="manufacture_date" class="echo" disabled="disabled"></input></td>
						</c:if>
						<c:if test="${obj.deviceType ne 1}">
							<td>仪器型号：</td>
							<td><input type="text" data-field="device_model" class="echo" disabled="disabled"></input></td>
						</c:if>
						
						<!-- <td>仪器型号：</td>
						<td><input type="text" data-field="device_model" class="echo" disabled="disabled"></input></td> -->
					</tr>
					<tr>
						<td>是否需要证书：</td>
						<td><input type="text" data-field="if_cert_" class="echo" disabled="disabled"></input></td>
						<td>检查人员：</td>
						<td>${LoginUser.userName }</td>
						<td class="non-empty">核验人员：</td>
						<td><vvise:select id="checkUser" name="p_checkUser" sqlname="getCheckUser" sqlparam="" className="full_select" /></td>
					</tr>
				</tbody>
			</table>
	
			<table id="tag2"  class="table-ltr" style="white-space: nowrap;">
	  			<caption>检查明细</caption>
				<tbody>
					<tr>
						<td>故障现象：</td>
						<td style="width: 210px;"><vvise:select id="faultId" name="faultId" sqlname="getFaultInfo" className="full_select" /></td>
						<td>更换配件：</td>
						<td><input type="hidden" name="partsId"></input> 
							<input type="text" name="partsName" style="width: 290px; cursor: pointer; float: left;" readonly="readonly"></input>
							<div class="add_icon" title="添加故障现象"></div>
							<div class="dev_icon" title="移除故障现象"></div></td>
					</tr>
				</tbody>
				<tfoot>
					<tr>
						<td class="non-empty">维修检查人员备注：</td>
						<td colspan="3"><input type="text" id="repairRemark" name="p_repairRemark"></input></td>
					</tr>
					<tr>
						<td class="non-empty">核验人员备注：</td>
						<td colspan="3"><input type="text" id="checkRemark"  name="p_checkRemark"></input></td>
					</tr>
				</tfoot>
			</table>
        </form>
	</body>
	<script type="text/javascript">
       	var resetF, validForm;
        $(function(){
        	/* 1. 动态添加行 */
        	$(document).delegate('.add_icon', 'click', function(){
        		var $tr = $(this).parents('tr').clone(true);
        		$tr.find('input').val('');
        		$(this).parents('tbody').append($tr.removeClass('error'));
        		$(this).hide();
        		$(this).siblings('.dev_icon').show();
			});
        	$(document).delegate('.dev_icon', 'click', function(){
        		$(this).parents('tr').remove();
			});
        	
        	
        	/* 1.1 选择更换配件 */
        	$(document).delegate('input[name="partsName"]', 'click', function(){
        		var index_ = $(this).parents('tr').index();
        		var id_ = $(this).siblings('input[name="partsId"]').val();
        		var otherId_ = $('#tag2 tbody tr').not($(this).parents('tr')).find('input[name="partsId"]').map(function(){if($(this).val()){return $(this).val();}}).get().join(',');
					
        		var pp = parent;
				var custId = '';
				pp.openWindow("更换配件",pp.width2,430,"${ctx}/myInspect/chooseParts?partsIds="+id_+"&otherIds="+otherId_,[{
					text:'确认',
					iconCls:'icon-ok',
					handler:function(){
						chooseParts(index_);
					}
				},{
					text:'取消',
					iconCls:'icon-no',
					handler:function(){
						pp.closeWindow('winDiv2');
					}
				}],'','winDiv2');
			});
        	
        	var chooseParts = function(idx){
        		var pp = parent;
    			var listFrame = pp.winFrame2;
    			var ids = "";
    			var ecForm = listFrame.document.all.ec;
    			if(!checkSelect(ecForm.id,true))
    				return;
    			ids = get_checkbox_values(ecForm.id,',');
    			var userId = "", userName = "";
    			var idd = ids.split(",");
    			for(var i in idd){
    				if(userId){
    					userId+=',', userName+='，';
    				}
    				userId += idd[i].split('||')[0];
    				userName += idd[i].split('||')[1];
    			}
    			
    			var tr_ = $('#tag2 tbody tr:eq('+idx+')');
    			tr_.removeClass('error');
    			$(tr_).find('input[name="partsId"]').val(userId);
    			$(tr_).find('input[name="partsName"]').val(userName);
    			pp.closeWindow('winDiv2');
        	};
        	
        	
        	
        	/* 2. 检测明细change事件 */
        	$('#tag2 tbody').delegate('select', 'change', function(){
        		var $tr = $(this).parents('tr').removeClass('error');
			});
        	
        	/* 3. 检索待检设备信息 */
        	$(document).delegate('.search_icon', 'click', function(){
        		var pp = parent;
        		var editFrame = pp.winFrame;
        		if(!pp.validData("deviceNo","请输入仪器编号！", 1, editFrame))
    				return;
        		
        		var deviceNo = editFrame.$('#deviceNo').val();
        		var result = pp.executeAjaxBySync('${ctx}/myInspect/getEquipment','p_deviceType=${obj.deviceType}&p_custId=${obj.custId}&p_deviceNo='+deviceNo);
				if(result == 'none'){
				 	pp.$.messager.alert('操作提示','未查询到待检设备，请重新输入','warning',function(){
					 	editFrame.$('#deviceNo').focus();
				 	});
					return;
				}else{
					var data = eval("("+result+")");
					var equ = data.columns;
					var logId = equ.log_id;
					if(!pp.isEmpty(logId)){
						pp.$.messager.alert('操作提示','该设备已检测，请重新输入','warning',function(){
						 	editFrame.$('#deviceNo').focus();
					 	});
						return;
					}
					
					$('.echo').each(function(){
						var field = $(this).data('field');
						var val = eval('equ.'+field);
						if(!val){
							val = '--'
						}
						$(this).val(val);
					});
					changeSelect('${ctx}/common/getSelectOptions?sqlname=getCheckUser&sqlparam='+equ.equ_id,'checkUser');
					$('#checkUser option').each(function(){
						if(this.value!='' && this.value!='${LoginUser.userId }'){
							this.selected = true;
						}
					});
				}
			});
        	
        	/* 4. 表单重置 */
        	resetF = function(){
        		$('.echo, #address').val('');
        		$('#checkUser').find("option:gt(0)").remove();
        		$('#tag2').find('input,select').val('');
        		$('#tag2 tbody tr:gt(0)').remove();
        		$('#tag2 tbody tr .add_icon').show();
        		$('#tag2 tbody tr .dev_icon').hide();
        	};
        	
        	/* 5. 表单非空验证 */
        	validForm = function(){
        		var pp = parent;
        		var editFrame = pp.winFrame;
        		if(!pp.validData("address","请输入地点！", 1, editFrame))
    				return false;
        		if(!pp.validData("deviceNo","请输入仪器编号！", 1, editFrame))
        			return false;
        		if(!pp.validData("checkUser","请选择核验人员！", 2, editFrame))
        			return false;
        		
        		var faultTR = editFrame.$('#tag2 tbody tr');
        		$(faultTR).removeClass('error');
    			if(faultTR.length>0){
    				for(var a=0; a<faultTR.length; a++){
    					var $tr = $(faultTR[a]);
    					var faultId = $tr.find('select[name="faultId"]').val();
    					var partsId = $tr.find('input[name="partsId"]').val();
    					if(pp.isEmpty(faultId)){
    						pp.$.messager.alert('操作提示','请选择故障现象！',"warning");
							$tr.addClass('error');
							return false;
    					}else if(pp.isEmpty(partsId)){
    						pp.$.messager.alert('操作提示','请选择更换配件！',"warning");
							$tr.addClass('error');
							return false;
    					}
    				}
    			}
    			
        		if(!pp.validData("repairRemark","请输入维修检测人员备注！", 1, editFrame))
        			return false;
        		if(!pp.validData("checkRemark","请输入核验人员备注！", 1, editFrame))
        			return false;
        		
        		return true;
        	};
        	
            //自动填充车牌数组
            var result = '${data}';
            var data = jQuery.parseJSON(result);
            $('#deviceNo').autocomplete(data, {
                max: 7, //列表里的条目数                 
                minChars: 1, //自动完成激活之前填入的最小字符                  
                width: 150, //提示的宽度，溢出隐藏                 
                scrollHeight: 180, //提示的高度，溢出显示滚动条     
                matchCase: false, //比较是否开启大小写敏感开关             
                matchContains: true, //包含匹配，就是data参数里的数据，是否只要包含文本框里的数据就显示                  
                autoFill: false, //自动填充                  //匹配的项所要发生的事件                 
                formatItem: function (row, i, max){
                   //row表示每一行的数据对象，i表示每一行的编号 max表示总的数据行数                     
                    return row.value + "[" + row.name + "]";
                }
            }).result(function (event, row, formatted) {
                $('#deviceNo').val(row.value);
            });
        });
    </script>
  	<script type="text/javascript" src="${ctx}/static/scripts/autocomplete/jquery-migrate-1.2.1.min.js"></script>
	<script type="text/javascript" src="${ctx}/static/scripts/autocomplete/jquery.autocomplete.js"></script>
</html>